package com.zr.beijian.redis;

import com.zr.beijian.JPARepository.BeiJianJapRepository;
import com.zr.beijian.bean.BeiJian;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

@Component
public class RedisAnnotation {
    @Autowired
    private BeiJianJapRepository beiJianJapRepository;
    @Cacheable(value = "query",key = "'findOne'+#id",condition = "")
    public BeiJian findOne(int id){
       return beiJianJapRepository.findOne(id);
    }
    @CachePut(value = "query",key="'findOne'+#beiJian.id")
    //更改后加删除全查缓存注解
    public BeiJian save(BeiJian beiJian){
        return beiJianJapRepository.save(beiJian);
    }
    @CacheEvict(value = "query" ,key="'findOne'+#id")
    public void delete(int id){
        beiJianJapRepository.delete(id);
    }
}
